import com.mysql.cj.jdbc.Driver;

import java.nio.file.attribute.UserPrincipalLookupService;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
//        try(Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/school")) {
//
//        }

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/school?user=root&password=");
            statement = connection.createStatement();
//            String sql = "insert into student values(15,'小呆瓜2','2001-08-15','男')";
            String find = "select * from student where id = 1";
            resultSet = statement.executeQuery(find);
            ArrayList<Integer> objects = new ArrayList<>();

            String sql1 = "insert into student(name,birth,gender)values('zs','1877-02-03','女')";
//            statement.

            ResultSetMetaData metaData = resultSet.getMetaData();
            while (resultSet.next()) {

                for (int i = 1; i <= metaData.getColumnCount(); i++) {
                    System.out.print(metaData.getColumnLabel(i) + "\t");
                }
                System.out.println();
                System.out.print(resultSet.getInt("id") + "\t");
                System.out.print(resultSet.getString("name") + "\t" +"  ");
                System.out.print(resultSet.getString("birth") + "\t");
                System.out.print(resultSet.getString("gender"));
            }
//            UserPrincipalLookupService
//            int row = statement.executeUpdate(sql);
//            System.out.println("共有"+row+"行被执行");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        finally {
            try {
                resultSet.close();
                statement.close();
                connection.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }

    }
}